<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>编辑</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-
scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <link rel="stylesheet" type="text/css" href="../css/y_index.css" />
    <style>
        /*上传图片*/

        .comment-photo label {
            display: inline-block;
            width: 1.24rem;
            height: 1.24rem;
            background: url(../img/uploadImg.png) no-repeat;
            background-size: 100% 100%;
            float: left;
            margin-right: 10px;
            margin-bottom: 10px;
        }
    </style>
</head>

<body>
<div class="bigBox">
    <div class="container">
        <form action="" enctype="multipart/form-data" method="post" name="form" id="form" onsubmit="return formSubmit()">
            <label class="flex_sb plr30 ptb30 bw mb20">
                <input type="file" name="files" hidden id="hd_img" onchange="localImg(this)" />
                <span class="col3 font15">公众号LOGO</span>
                <em class="flex_a">
                    <img class="mr20 hd_img" src="" id="headimg"/>
                    <img src="../img/y_arrow_right.png" class="arrow_r"/>
                </em>
            </label>
            <!-- <li class="bw flex_sb p20 mtb20">
            <span>公众号LOGO</span>
            <ul class="flex_a">
                <img src="../img/y_11.png" style="width: 1rem;height: 1rem" />
                <img class="ml20" src="../img/y_arrow_right.png" style="width:.12rem;height: .22rem" />
            </ul>
        </li> -->
            <li class="bw p20 bdb flex_sb">
                <span>公众号名称</span>
                <input type="text" name="id" hidden>
                <input class="tae name" type="text" name="name" placeholder="请输入" tip-text="公众号名称" required/>
            </li>
            <li class="bw p20 bdb flex_sb">
                <span>AppID</span>
                <input class="tae AppID" type="text" name="appId" placeholder="请输入" tip-text="AppID" required />
            </li>
            <li class="bw p20 bdb flex_sb">
                <span>AppSecret</span>
                <input class="tae AppSecret" type="text" name="appSecret" placeholder="请输入" tip-text="AppSecret" required />
            </li>
            <li class="bw p20 bdb flex_sb">
                <span>免费领取代码</span>
                <input class="tae freeGet" type="text" name="freeCode" placeholder="请输入" tip-text="免费领取代码" required/>
            </li>
            <li class="bw p20 bdb flex_sb">
                <span>微信号</span>
                <input class="tae weChatNumber" type="text" name="wxCount" placeholder="请输入" tip-text="微信号" required />
            </li>
            <li class="bw p20 bdb flex_sb">
                <span>原价</span>
                <input class="tae prime" type="number" name="originalPrice" placeholder="请输入" tip-text="原价" required />
            </li>
            <li class="bw p20 bdb flex_sb">
                <span>分成单价</span>
                <input class="tae unit_price" type="number" name="deductPrice" placeholder="请输入" tip-text="分成单价" required />
            </li>
            <li class="bw p20 bdb flex_sb">
                <span>每日关注上限</span>
                <input class="tae max_follow" type="number" name="upperLimit" placeholder="请输入" tip-text="每日关注上限" required />
            </li>
            <!--<li class="bw p20 bdb flex flex_column">-->
                <!--<span>上传广告图</span>-->
                <!-- 上传图片 -->
                <!--<div class="bw flex" style="margin:0.5rem 0">
                    <form class="bw">
                        <div class="pic">
                            <div class="comment-photo">
                                <div class="pic_box" id="pic_box" style="padding: .2rem;">
                                    <label class="a-upload dib" style="position: relative;">
                                        <input type="file" name="pictures[]" class="upLoadImg" tip-text="图片" onchange="upLoadImg(this,'pic_box',6)" accept="image/*" capture="camera" multiple hidden/>
                                    </label>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>-->
                <!-- <input class="tae" type="text" name="name" placeholder="请输入" tip-text="上传广告图" required /> -->
                <!-- </li>-->
                <!--   <input  type="text" name="deviceId" value=""/>-->
                <!--<input  type="text" name="imgUrl" value="" hidden=""/>-->
                <!--<input  type="text" name="deviceNo" value="" hidden=""/>-->
                <!--<input  type="text" name="status" value="1" hidden=""/>-->
            <li class="bw p20 bdb flex_sb">
                <span>状态</span>
                <div class="flex_a">
                    <label class="flex mr70">
                        <input type="radio" type="hidden" name="status" class="radioBox status1" value="1"  />
                        <span class="roudBox border mr20"></span>上架
                    </label>
                    <label class="flex">
                        <input type="radio" type="hidden" name="status" value="2"  class="radioBox status2" />
                        <span class="roudBox border mr20"></span>下架
                    </label>
                </div>
            </li>
        </form>
        <div class="main_btn" onclick="formSubmitSelf(this,'form','/api/officialAccounts/update')">确定</div>
    </div>
</div>
</body>

</html>
<script src="../js/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/dlc.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="../js/JForm.js"></script>
<script src="../js/swiper.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="../js/jquery.form.js"></script>
<script src="https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.0/alipayjsapi.inc.min.js"></script>
<!--公司的常用函数封装-->
<script>
    // 初始化
    // var localImg;
    // $('input[name="deviceNo"]').val(getUrlParam('deviceNo'))
    // console.log($('input[name="deviceNo"]').val())
    //
    //
    // $('input[name="check"]').change(function(){
    //     console.log($('input[name="check"]:checked').val())
    //     $('input[name="status"]').val($('input[name="check"]:checked').val()*1)
    // })



    //dlctipbox.loading('载入中...');
    //dlc_request('/App/Vip/api', { api_name: 'vip_info' }, function(res) {
    //  dlctipbox.clear();
    //  if (res.code == 1) {
    //      $('#headimg').attr('src', res.data.headimg);
    //      $('.nickname').text(res.data.nickname);
    //  } else {
    //      console.log(res);
    //  }
    //});

    //查询公众号详情
    dlc_request('/api/officialAccounts/info', { id: getUrlParam('id')}, function(res) {
        console.log(res);
        $('#headimg').attr('src',res.data.imgUrl);
        $('.name').val(res.data.name);
        $('.AppID').val(res.data.appId);
        $('.AppSecret').val(res.data.appSecret);
        $('.freeGet').val(res.data.freeCode);
        $('.weChatNumber').val(res.data.wxCount);
        $('.prime').val(res.data.originalPrice);
        $('.unit_price').val(res.data.deductPrice);
        $('.max_follow').val(res.data.upperLimit);
        $('.status'+res.data.status).attr('checked','checked');


    });

    $('#hd_img').on('change', function() {
        $('#form').submit();
    });

    //保存
    $('.main_btn tap').click(function() {
        var nickname = $('.nickname').val();
        if (isNull(nickname)) {
            dlctipbox.show('请输入用户名');
        } else {

        }
    });

    function formSubmit() {
        $('#form').ajaxSubmit({
            type: 'POST',
            url: dlcUrl() + '/api/upload',
            dataType: 'json',
            beforeSubmit: function() {
                var imgValue = $('#hd_img').val();
                if (imgValue == '') {
                    dlctipbox.show('请选择图片');
                    return false;
                }
                dlctipbox.loading('上传中...');
            },
            success: function(res) {
                dlctipbox.clear();
                if (res.code == 1) {
                    dlctipbox.show('修改成功');
                    $('#headimg').attr('src', localImg);
                    console.log(res.data.imgPath[0])
                    $('input[name="imgUrl"]').val(res.data.imgPath[0])
                } else {
                    dlctipbox.show(res.msg);
                }
            },
            error: function(err) {
                console.log(err);
            }
        });
        return false; //阻止表单默认提交
    }

    function localImg(that) {
        console.log(getObjectURL(that.files[0]));
        localImg = getObjectURL(that.files[0]);
    }

    function formSubmitSelf(obj, formId, url, url2) {
        $('input[name="id"]').val(getUrlParam('id'));
        $('#' + formId).ajaxSubmit({
            type: 'post',
            url: dlcUrl() + url,
            dataType: 'json',
            beforeSubmit: function() {

                 if(isNull($('input[name="name"]').val())){
                    dlctipbox.show('请填写公众号名字')
                }else if(isNull($('input[name="appId"]').val())){
                    dlctipbox.show('请填写appId')
                }else if(isNull($('input[name="appSecret"]').val())){
                    dlctipbox.show('请填写appSecret')
                }else if(isNull($('input[name="freeCode"]').val())){
                    dlctipbox.show('请填写免费领取代码')
                }else if(isNull($('input[name="wxCount"]').val())){
                    dlctipbox.show('请填写微信号')
                }else if(isNull($('input[name="originalPrice"]').val())){
                    dlctipbox.show('请填写原价')
                }else if(isNull($('input[name="deductPrice"]').val())){
                    dlctipbox.show('请填写分成单价')
                }else if(isNull($('input[name="upperLimit"]').val())){
                    dlctipbox.show('请填写每日关注上限')
                }
                dlctipbox.loading('加载中');
            },
            success: function(res) {
                dlctipbox.clear();
                $(obj).removeAttr('disabled');
                if (res.code == 1) {
                    dlctipbox.show('添加成功');
                    //if (url2 && url2 !== '') {
                    setTimeout(function() {
                        //  window.location.href = url2;
                        history.back()
                    }, 3000);
                    //}
                } else {
                    dlctipbox.show(res.msg);
                }
            },
            error: function(res) {
                dlctipbox.show(res.msg);
                console.log('网络异常,请刷新');
            }
        })
    }
    // 上传图片
    //解决上传图片时capture="camera"在安卓与IOS的兼容性问题（在IOS只能拍照，不能选相册）
    var ua = navigator.userAgent.toLowerCase(); //获取浏览器的userAgent,并转化为小写——注：userAgent是用户可以修改的
    var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1); //判断是否是苹果手机，是则是true
    if (isIos) {
        $("input:file").removeAttr("capture");
    };
</script>